package com.yt.system.controller;


import com.yt.system.domain.Keyresults;
import com.yt.system.domain.ObjectiveKeyresults;
import com.yt.system.service.KeyresultsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("KR")
@RequestMapping("/keyresults")
@RestController
public class KeyresultsController {
    @Autowired
    KeyresultsService keyresultsService;

    //删除
    @ApiOperation(value = "根据oid删除kr")
    @RequestMapping(value = "/deleteKeyresults/{id}",method = RequestMethod.GET)
//    @RequestMapping("deleteKeyresults/{id}")
    public int DeleteObjective(@PathVariable int id){
        return keyresultsService.DelK(id);
    }

    //form-data提交，更新
    @ApiOperation(value = "更新kr")
    @RequestMapping(value = "/updateKeyresults",method = RequestMethod.POST)
//    @RequestMapping(value = "/updateKeyresults")
    public int updateObjective(Keyresults obj){
        return keyresultsService.UpdK(obj);
    }

    //    json数据类型提交，插入
    @ApiOperation(value = "添加kr")
//    @RequestMapping(value = "/addKeyresults",method = RequestMethod.POST)
    @RequestMapping(value = "/addKeyresults", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public int addObjective(@RequestBody Keyresults obj){
        return keyresultsService.InsK(obj);
    }

    //根据oid查询kr
    @ApiOperation(value = "根据oid查询kr")
    @RequestMapping(value = "/getkrByOid/{oid}",method = RequestMethod.GET)
    @ResponseBody
    public List<ObjectiveKeyresults> selectKrByOid(@PathVariable("oid") int oid){
        return keyresultsService.selectKrByOid(oid);
    }





}
